<div class="box">
    <div class="box-content">
        <fieldset>
            <legend>权限项管理</legend>
            <form id="addAccessForm" style="margin: 1em" class="form-horizontal">
                <input type="hidden" name="id" value="<{$role.id}>"/>

                <div class="form-group" style="border-bottom: 1px dashed blue">
                    <label class="col-sm-1 control-label">角色</label>
                    <div class="col-sm-2"><input type="text" class="form-control" value="<{$role.name}>[<{$role.remark}>]" name="title" readonly/></div>
                </div>
                <{foreach from=$module_level_2 item="Lv2"}>
                <div class="form-group" style="padding-bottom:0.4em">
                    <label class="col-sm-1">
                        <div class="checkbox">
                            <label>
                                <input type="checkbox"  class="check-all-box"> <{$Lv2.title}>
                                <i class="fa fa-square-o"></i>
                            </label>
                        </div>

                    </label>
                    <div class="col-sm-10">
                        <{foreach from=$Lv2['sub'] item="Lv3"}>
                        <div class="checkbox col-sm-2">
                            <label>
                                <input value="<{$Lv3['id']}>" type="checkbox" name="access[]" <{if $Lv3.checked eq 1 }>
                                checked <{/if}> > <{$Lv3.title}>
                                <i class="fa fa-square-o"></i>
                            </label>
                        </div>

                        <{/foreach}>
                    </div>
                </div>
                <{/foreach}>

                <div class="form-group">
                    <div class="col-sm-1 "></div>
                    <div class="col-sm-2"><input type="button" id="submit" class="btn btn-primary btn-block" value="提交">
                    </div>
                </div>
            </form>

        </fieldset>
    </div>
</div>
<script>
    var $obj
    $(document).ready(
            function () {
                $('.check-all-box').on('click', function (e) {
                    $obj = $(this);
                    var attr = $(this).prop('checked');
                    if (attr) {

                        $obj.prop("checked", true);
                        $obj.parents('.col-sm-1').next().find(':checkbox').prop("checked", true);
                    } else {
                        $obj.removeAttr('checked', false);
                        $obj.parents('.col-sm-1').next().find(':checkbox').prop('checked', false)
                    }
                    e.stopPropagation();
                });
            }
    );
    $("#submit").on('click', function () {
        var param = $("#addAccessForm").serialize();
        $.post("<{u('Dev/SysRole/accessUpdate')}>", param, function (res) {
            layer.msg(res.msg);
            if (res.status == 0) {
                location.reload();
            }
        });
    });
</script>